home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / fsattach / RCS / exec.c,v < prev    next >
Encoding:
Text File  |  1989-06-08  |  4.4 KB  |  249 lines

  1. head     1.3;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.3
  10. date     89.06.07.22.14.25;  author jhh;  state Exp;
  11. branches ;
  12. next     1.2;
  13.  
  14. 1.2
  15. date     89.04.10.11.12.16;  author jhh;  state Exp;
  16. branches ;
  17. next     1.1;
  18.  
  19. 1.1
  20. date     89.03.06.12.58.35;  author jhh;  state Exp;
  21. branches ;
  22. next     ;
  23.  
  24.  
  25. desc
  26. @
  27. @
  28.  
  29.  
  30. 1.3
  31. log
  32. @Spring cleaning - new mount table format, bug fixes
  33. @
  34. text
  35. @/* 
  36.  * exec.c --
  37.  *
  38.  *    Routines that provide a nice interface for execing routines with a
  39.  *    variable number of parameters.
  40.  *
  41.  * Copyright 1989 Regents of the University of California
  42.  * Permission to use, copy, modify, and distribute this
  43.  * software and its documentation for any purpose and without
  44.  * fee is hereby granted, provided that the above copyright
  45.  * notice appear in all copies.  The University of California
  46.  * makes no representations about the suitability of this
  47.  * software for any purpose.  It is provided "as is" without
  48.  * express or implied warranty.
  49.  */
  50.  
  51. #ifndef lint
  52. static char rcsid[] = "$Header: /sprite/src/admin/fsattach/RCS/exec.c,v 1.2 89/04/10 11:12:16 jhh Exp $ SPRITE (Berkeley)";
  53. #endif /* not lint */
  54.  
  55. #include "fsattach.h"
  56. #include <varargs.h>
  57.  
  58.  
  59. static char     *argArray[MAX_EXEC_ARGS];
  60. static int    argCount;
  61. static char    *routineName;
  62. /*
  63.  *----------------------------------------------------------------------
  64.  *
  65.  * StartExec --
  66.  *
  67.  *    Initialize data structures for doing an exec. The routine name must
  68.  *    point to an area of storage that is not modified until DoExec()
  69.  *    is called.
  70.  *
  71.  * Results:
  72.  *    None.
  73.  *
  74.  * Side effects:
  75.  *    Arg count is set to 1, routine name stored and first arg stored.
  76.  *
  77.  *----------------------------------------------------------------------
  78.  */
  79.  
  80. void
  81. StartExec(routine, firstArg)
  82.     char    *routine;
  83.     char    *firstArg;
  84. {
  85.     routineName = routine;
  86.     argArray[0] = firstArg;
  87.     argCount = 1;
  88. }
  89.  
  90. /*
  91.  *----------------------------------------------------------------------
  92.  *
  93.  * AddExecArgs --
  94.  *
  95.  *    The list of arguments is added to the array to be passed to exec.
  96.  *    The storage used by the arguments must not be modified until
  97.  *    DoExec is called.
  98.  *
  99.  * Results:
  100.  *    None.
  101.  *
  102.  * Side effects:
  103.  *    The argument array and arg count are modified.
  104.  *
  105.  *----------------------------------------------------------------------
  106.  */
  107. #ifdef lint
  108. /*VARARGS*/
  109. /*ARGSUSED*/
  110. void
  111. AddExecArgs(foo)
  112.     char    *foo;
  113. {}
  114.  
  115. #else
  116.  
  117. void
  118. AddExecArgs(va_alist)
  119.     va_dcl
  120.  
  121. {
  122.     char    *string;
  123.  
  124.     va_list    args;
  125.  
  126.     va_start(args);
  127.     for(string = va_arg(args, char *);
  128.     string != NULL; 
  129.     string = va_arg(args, char *), argCount++) {
  130.  
  131.     if (argCount >= MAX_EXEC_ARGS) {
  132.         (void) fprintf(stderr, "Too many args to exec.\n");
  133.         return;
  134.     }
  135.     argArray[argCount] = string;
  136.     }
  137. }
  138. #endif
  139.  
  140. /*
  141.  *----------------------------------------------------------------------
  142.  *
  143.  * DoExec --
  144.  *
  145.  *    Calls Exec with the arguments built up so far.
  146.  *
  147.  * Results:
  148.  *    Process id of child process, -1 if there was an error.
  149.  *
  150.  * Side effects:
  151.  *    Child process is forked.
  152.  *
  153.  *----------------------------------------------------------------------
  154.  */
  155.  
  156. int
  157. DoExec()
  158. {
  159.     int            pid;
  160.     int            i;
  161.  
  162.     if (argCount >= MAX_EXEC_ARGS) {
  163.     (void) fprintf(stderr, "Too many args to exec.\n");
  164.     return -1;
  165.     }
  166.     argArray[argCount] = NULL;
  167.     if (verbose) {
  168.     for (i = 0; i < argCount; i++) {
  169.         printf("%s ", argArray[i]);
  170.     }
  171.     putchar('\n');
  172.     }
  173.     if (printOnly) {
  174.     return 0;
  175.     }
  176.     pid = fork();
  177.     if (pid == 0) {
  178.     (void) execvp(routineName, argArray);
  179.     (void) fprintf(stderr, "Exec failed.\n");
  180.     (void) perror("");
  181.     (void) _exit(EXEC_FAILED);
  182.     } 
  183.     return pid;
  184. }
  185.  
  186. @
  187.  
  188.  
  189. 1.2
  190. log
  191. @First working version
  192. @
  193. text
  194. @d18 1
  195. a18 1
  196. static char rcsid[] = "$Header: /sprite/users/jhh/fsattach/RCS/exec.c,v 1.1 89/03/06 12:58:35 jhh Exp Locker: jhh $ SPRITE (Berkeley)";
  197. d125 2
  198. a126 2
  199.     int        pid;
  200.     int        i;
  201. d140 1
  202. a140 1
  203.     return -1;
  204. @
  205.  
  206.  
  207. 1.1
  208. log
  209. @Initial revision
  210. @
  211. text
  212. @d2 1
  213. a2 1
  214.  * module.c --
  215. d4 2
  216. a5 1
  217.  *    Description.
  218. d18 1
  219. a18 1
  220. static char rcsid[] = "$Header: /sprite/lib/forms/RCS/proto.c,v 1.2 89/01/07 04:12:18 rab Exp $ SPRITE (Berkeley)";
  221. d47 1
  222. a47 1
  223. StartExec(routine)
  224. d49 1
  225. d52 1
  226. a52 1
  227.     argArray[0] = routine;
  228. d62 2
  229. d114 1
  230. a114 1
  231.  *    None.
  232. d117 1
  233. a117 1
  234.  *    Exec is called.
  235. d133 1
  236. a133 2
  237.     if (printOnly) {
  238.     printf("Execing %s with parameters:\n", routineName);
  239. d138 2
  240. d142 1
  241. a142 1
  242.     pid = vfork();
  243. d144 4
  244. a147 3
  245.     (void) execv(routineName, argArray);
  246.     (void) fprintf(stderr, "YOW! Exec returned.\n");
  247.     (void) _exit(HARDERROR);
  248. @
  249.